<?php

if(!defined("IN_PHPSCUP"))exit("hacking");
/**
 *    控制器基础类
 */
class BaseApp {
	/* 建立到视图的链接 */
	var $_view = null;

	var $_curr_action = null;

	var $_nav = array (); //导航数组

	var $_model_queue = array (); //控制层实体队列

	function __construct() {
		$this->BaseApp();
	}

	function BaseApp() {
		$this->_init_view();
		$this->_init_lang_view();
	}

	function _init_lang_view() {

	}

	function do_action($action) {
		if ($action && $action {
			0 }
		!= '_' && method_exists($this, $action)) {
			$this->_curr_action = $action;
			$this->_run_action(); //运行动作
		} else {
			exit ('missing_action');
		}
	}

	function _run_action() {
		$action = $this->_curr_action;
		$this-> $action ();
	}

	/**
	 *    初始化视图连接
	 */
	function _init_view() {
		if ($this->_view === null) {
			$this->_view = & get_view();
		}
	}

	/**
	 *    取得控制模块实体	
	 */
	function & _model($name) {

		if (!isset ($this->_model_queue[$name])) {
			$model_file = $GLOBALS['SCup']->SCup_model_root . "/{$name}.model.php";
			if (!is_file($model_file)) {
				exit ('Missing model');
			}
			require ($model_file);
			$model_class_name = ucfirst($name) . 'Model';
			$this->_model_queue[$name] = new $model_class_name ();

		}

		return $this->_model_queue[$name];
	}

	/**
	 *    给视图传递变量
	 */
	function assign($k, $v = null) {
		$this->_init_view();
		if (is_array($k)) {
			exit ('unable_array');
		} else {
			$this->_view->assign($k, $v);
		}
	}

	/**
	 *    显示视图
	 */
	function display($n, $c = '') {
		$this->_init_view();
		$this->_view->display($n, $c);
	}

	function index() {
		echo 'Hello! PHPSCup';
	}

	function destruct() {

	}
}
?>